@ComponentScan、@EnableFeignClients和@MapperScan注解笔记 |
您所在的位置:网站首页 › enablefeignclients 注解作用 › @ComponentScan、@EnableFeignClients和@MapperScan注解笔记 |
@ComponentScan:此注解是用来管理容器中的bean,即是管理项目中类的依赖关系, 注意此注解并不创建类的实例; 默认情况下此注解扫描本工程下的所有包, 但是在springBoot的分布式中如果需要用到别的微服务工程中的实例,那么就要写为如下的形式。注意要加上本工程。 因为当使用 basePackages时,此注解就不会使用默认的扫描路径了。 @ComponentScan(basePackages = { "com.wisdombud.dth.boss.customer", "com.wisdombud.dth.boss.his", "com.wisdombud.dth.boss.product.srv", "com.wisdombud.dth.boss.product.mapper" })@EnableFeignClients: 此注解的作用是扫描标记了@FeignClient的接口并创建实例bean,默认扫描并创建所在工程下的包。如果在springBoot的分布式中需要用到别 的微服务的工程的接口实例,那么就要写成如下的形式。注意此注解并不管理bean的依赖的关系 @EnableFeignClients( basePackages = { "com.wisdombud.dth.boss.customer", "com.wisdombud.dth.boss.his", "com.wisdombud.dth.boss.product.srv" })@MapperScan: 此注解是扫描被此注解中声明的mapper路径下的*mapper.xml文件,读取文件配置,并根据此文件中的mapper接口路径创建bean实例。如下写法。 /*** * 功能:客户datasource 配置. * *date:2018 年10月11日 下午2:17:31 * ** * * @author * joseph * @since * JDK 1.8 */ @Configuration @EnableConfigurationProperties @MapperScan(basePackages = "com.wisdombud.dth.boss.customer.mapper", sqlSessionTemplateRef = "custSqlSessionTemplate") public class DataSourceCustConfig { @Bean @ConfigurationProperties(prefix = "spring.jta.atomikos.datasource.cust") @Primary public AtomikosDataSourceBean custDataSource() { return new AtomikosDataSourceBean(); } @Bean @Primary public SqlSessionFactory custSqlSessionFactory(@Qualifier("custDataSource") DataSource dataSource) throws Exception { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); return bean.getObject(); } @Bean @Primary public SqlSessionTemplate custSqlSessionTemplate( @Qualifier("custSqlSessionFactory") SqlSessionFactory sqlSessionFactory) throws Exception { return new SqlSessionTemplate(sqlSessionFactory); } }
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |